#pragma once
#include "effect.h"
#include <string>
#include <map>
#include "signal_slot.h"

namespace krryn{
namespace view{
	class shader;

	enum shader_type{
		vs,
		ps,
		shader_type_count
	};

	struct compile_error_args{
		std::string m_ErrorMessage;
	};

	class shader_auto_parameter{
	public:
		virtual void update() {}
		virtual std::string get_name() = 0;
		virtual void configure_shader(shader_type a_Type, shader &a_Shader) = 0;
	};

	class renderer;
	class shader_catalog{
	public:
		shader_catalog(renderer &a_Renderer);
		virtual ~shader_catalog() {}
		shader *get_shader(const std::string &a_Filename);

		krryn::core::signal<compile_error_args*> m_OnCompileError;

		void register_auto_parameter(shader_auto_parameter *a_AutoParameter);
		void update();
		bool is_error_shader(shader &a_Shader);

		void set_error_shaders(const std::string &a_Error = "error", const std::string &a_Warning = "warning");

		shader_auto_parameter * const get_auto_parameter(const std::string &a_Name);

	protected:
		virtual shader *load_shader(const std::string &a_Filename) = 0;

	private:
		std::map<std::string, shader_auto_parameter*> m_AutoParameters;
		std::map<std::string, shader*> m_Shaders;

		std::string m_ErrorShader;
		std::string m_WarningShader;

		renderer &m_Renderer;
	};
}
}